Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp756049rwd; Thu, 15 Jun 2023 01:23:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6IF95bRLdCdRYuaKoGLmiuH1Y2uKRtVDAwPY2qmYn++30puSNj78mDCiDMi/suAgI0ahyh X-Received: by 2002:a2e:87d9:0:b0:2b2:5d2:ce5f with SMTP id v25-20020a2e87d9000000b002b205d2ce5fmr7816460ljj.50.1686817421909; Thu, 15 Jun 2023 01:23:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686817421; cv=pass; d=google.com; s=arc-20160816; b=D31zk2tZKQ/zdA3q3QumTs56OY4hst5hEF95GSuk6nSGN12agInmDnlmqasbJOC/Au UboLmxZKwkY3rvQA/G3rIo6inr3fFLrg50A1DMFdQNVUGSv56A8yuINe1/RqcaHJuI6Y NE1D+XSqHz7O0SptQtDFqXST5VaIKPIZa6+wzXy/BxNb4N3HB0PkgdAdBu0rNX8hcKZ1 cV5BhIELp3Lb8UOfSH6Iyphx+Bn/SEUnG9DfffuoEEMkhPZO5iNMoGHeUeyIJlNHFjsA C+DD9lFwKRuaWYOm7fniJLTOskHdW7zqQPg55nPV0Yf1rs4GVLqakc83qMsMCc0GHH9K 8NSQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:subject:from:references:cc:to:content-language :user-agent:date:message-id:dkim-signature; bh=QDiZfHHu5UuW89C3SOpWMjNWGIsDXjq48VYLFVUKlr0=; b=HqanHBBS67XCh4mtbvVYo8a4X/2o/z2+7YpSKM6YLUgOxtwGaHyJX9rp38B5pVq61s P/d9IuwtEqnrKRd92kD6fQvr7HLic1zVXWiUhhpaw6y6kKIT7XUqZTVWPhHHAXp/+zpn mG65c8Lh2RR4Jp12j0Omk6cbv0JdEsx6vK5Y1pcfv8lXTfgFijP+R53UKdgJ35sZ/3h3 +1N7L838Qjjl1ah1myELUhMuuvEHr6KiVpmdTtnK4+CNDb4hq+HVNpTNVZFGAEOilXRk y/0Bdekj1l5dzdp8umZmfVOqHskzpEU9snYCdxa+iWIOX3Y7DsNYdFwTv13Vz3IZivyZ wDUQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=selector1 header.b=SBwDYtIb; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a2-20020a50ff02000000b00518498576a5si4327510edu.16.2023.06.15.01.23.17; Thu, 15 Jun 2023 01:23:41 -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=@suse.com header.s=selector1 header.b=SBwDYtIb; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245296AbjFOHtQ (ORCPT + 99 others); Thu, 15 Jun 2023 03:49:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245137AbjFOHs6 (ORCPT ); Thu, 15 Jun 2023 03:48:58 -0400 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2049.outbound.protection.outlook.com [40.107.14.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E41002D79; Thu, 15 Jun 2023 00:48:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g+1rQs5j0ZVpuFs9vhKENu7m6ESlKIlAlwVLgFiPOFmjWg0Vsgo84K0MjW75usnYOUclInREVl2TSklJuyzJreE/B+BMShkqIoB+yYRl2+Kabh5KVpi8dsKiphu9LZugFrJCY+q3z42tfoGsSrQLI7+VuGzt3vqLYnbDTHx6EAFHmDN+Xoa2Fa1Tqk7VsV9aCqMvKdYZBnbQrQb8M2iFk/QEaOPHgk79Aim9JHEJ6FlXLnNpkQXqH+QhVuIQoG/zNG3FZDA8CjEbFlDVTQbERfuOO1l2lmQpXmyIXOjdV8gyLL6VgFU21r++69rVPbbXBy89+rY954QlvjQB4W8hxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QDiZfHHu5UuW89C3SOpWMjNWGIsDXjq48VYLFVUKlr0=; b=lnvLZvQx3LIh6L9nSc4nASBfTf/N9SpdNKKsAvCG9QA9QGDnwWOatMMLR6b3YL1Vm7SEjH7yDqBOIzxIB6BcLSlv9CdJ0tYfZ5ew/e1a5uqpdMCsCIWEPDL6jHoKm0LfGbStni7n0OKgGBfB71tow8mBIr4j7Bo8MdSfPsHGpN7ZxDnptTE0Uo4xLJcUTLE9eIXVO02USSvQ1nA4qLECr58Fb4L5NzEtb164eyay5eh212ddQg7lTTQ3t4zCZ6991p/zba1wKak7TCmB8gx0ZlVD1vpMXy53i0mpAu5t3Z/2NCraDGufe5HRP2/nUhVBMZA0JDkxtRe0MQABMRiEuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QDiZfHHu5UuW89C3SOpWMjNWGIsDXjq48VYLFVUKlr0=; b=SBwDYtIbDmM0lXb4y+qXj+e6fvPWGrdXnZgR7K/8uTEMX3k2tAX0TaCt45rGKDhbEuCfLOZ5OOgxKD29+JoYE3qhJgGTaYvSxzk1nsLx4l3nqWTpl+MkdWrUfVjN76CuFVF7uQ8MEwO8id0e81wy+Uk9uFHeMc7JX6t/lIpzby9Ye8pfkTyyxuiSKQiuTJn/RikykWZ8QnBoBv1VlKXEzYPTo8cCdAgLtWy48qWupRGGiMGDmUrH6Lt1SEsxmYCouYFgIBLEMvDSgBv4N/Fiw4Ki/B4iPdUfavBZSNRPfUJHxgsb8Vzx0oMLFzDNBdubnl9ZwlIuGQhN/dNQ7afEOg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from PA4PR04MB7790.eurprd04.prod.outlook.com (2603:10a6:102:cc::8) by AM0PR04MB6916.eurprd04.prod.outlook.com (2603:10a6:208:185::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Thu, 15 Jun 2023 07:48:21 +0000 Received: from PA4PR04MB7790.eurprd04.prod.outlook.com ([fe80::66a2:8913:a22a:be8d]) by PA4PR04MB7790.eurprd04.prod.outlook.com ([fe80::66a2:8913:a22a:be8d%4]) with mapi id 15.20.6500.025; Thu, 15 Jun 2023 07:48:21 +0000 Message-ID: Date: Thu, 15 Jun 2023 10:48:17 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Content-Language: en-US To: Kai Huang , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: linux-mm@kvack.org, dave.hansen@intel.com, kirill.shutemov@linux.intel.com, tony.luck@intel.com, peterz@infradead.org, tglx@linutronix.de, seanjc@google.com, pbonzini@redhat.com, david@redhat.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, ying.huang@intel.com, reinette.chatre@intel.com, len.brown@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 References: <4e108968c3294189ad150f62df1f146168036342.1685887183.git.kai.huang@intel.com> From: Nikolay Borisov Subject: Re: [PATCH v11 12/20] x86/virt/tdx: Allocate and set up PAMTs for TDMRs In-Reply-To: <4e108968c3294189ad150f62df1f146168036342.1685887183.git.kai.huang@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: ZR0P278CA0151.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:41::12) To PA4PR04MB7790.eurprd04.prod.outlook.com (2603:10a6:102:cc::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PA4PR04MB7790:EE_|AM0PR04MB6916:EE_ X-MS-Office365-Filtering-Correlation-Id: ae2c5d3f-59cf-429c-6065-08db6d74e3b4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HZ1929BrvtogSeRZi6/6+Vs/ECJU0gOIH8NbbB3ZOSxmEMU4UsvNilP6PcwwYRJdvBGjX/opiiDTyTMTbBM+1nksT/PYxNKAVrB2BSOmhFSsTDQZjI9ajfKdBPTcT+J1c3w34UoRyZ0j7MeZuzRr3O9RPds1Tc0QAcDr/qxKdZjQXKZDf7ypl3dY9OACoidyQiUP2FRypeG0wpVQ8aLS5R6BJFwHLxy9+j/ZwyGxho2r+FChJSNwLjj4I+SDmIRtUvgkXZLCwBrF8xJgMj4M0okZAYtUrGbIc6UzmvqLoeEZy0EgC5rZTjLO/xh68E+eL2YKJp+ZMHcBC5r0tKoFmr7jFckCyT6A4OT7XS8R4FE4jRMw2q+MTV9lEfZDLVbuFMIjC1qaSVzDw/56ZW9NAbUqI7xdpauS1HJ8PcjooN7Zg5ovuArTFrV0u2tERIr6fVjuHcHmoVqmxWMeyz77+BWaazDi0tNWAsoGkxYB4dEgPStZlSZ6dsKHcJ6y4Sx0KC0sGvfzjfop1ZsC12BKigBWC3gh1s8NKoRpzXX5b9uMUdNJBPIxSzwMMKD4VdxSUt181dg/qu8w3iil4oqqmpypVIvrCnf8FaPKSurck+F2QVqF1uwyxD/FlgYTpUXg0JoTCfPIfZwCjAKSffgv4pTIVa1X7965PNyoxpilpwE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PA4PR04MB7790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(396003)(366004)(376002)(346002)(39860400002)(136003)(451199021)(36756003)(6506007)(6512007)(186003)(478600001)(6666004)(6486002)(2906002)(316002)(41300700001)(8936002)(86362001)(31696002)(31686004)(5660300002)(8676002)(7416002)(38100700002)(2616005)(66946007)(83380400001)(66476007)(66556008)(4326008)(17423001)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?eWxESjV1bDAxQnJFcFJOSjRPTkFPd2cwaW5QY0w0a1BkQXdvVi82STlJZ2ox?= =?utf-8?B?emFNWlhEa0Q1bVFnTkVUWDVQallSMkw5NHZnd2dGOXorNDI4ZndxUVlVMmMv?= =?utf-8?B?YlYyeU1sUlJ5WURONnBPTTBhS2s0Ynh5SXZmQmJIQWFCNFc1YzBJdlhVcW51?= =?utf-8?B?O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lmZVBHY0lqeHVP?= =?utf-8?B?bGlHSUtVMFltVjFZL3d3N2FSQW5ic29QaW1lQnpCckRKRXg4ZWY0Y1pRYlVK?= =?utf-8?B?eXVGSW00QmdzejB4NHhCNmdNMG8ycXpVc29Tc0JnVThETFY2MDRPZzB4bEVk?= =?utf-8?B?UEhhc0t5NlZKSU5FK2RNRkJNN01VTXZNOXU5RS9ncVc5M0RydVpjVnNQY3pa?= =?utf-8?Q?pFX+176lgU8kLuFh+20Gj5BtjrKosGS66A25wcudhCSh?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ae2c5d3f-59cf-429c-6065-08db6d74e3b4 X-MS-Exchange-CrossTenant-AuthSource: PA4PR04MB7790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jun 2023 07:48:20.8678 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eClDVououNUybRG+ikqCD1i5V4S/aGL8x6Ge7ywyRWTTLnfb6hw8wfq+R19fdNZagwLExHYWQ4AfB4BuePfmgw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6916 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 4.06.23 г. 17:27 ч., Kai Huang wrote: > /* > * Construct a list of TDMRs on the preallocated space in @tdmr_list > * to cover all TDX memory regions in @tmb_list based on the TDX module > @@ -487,10 +684,13 @@ static int construct_tdmrs(struct list_head *tmb_list, > if (ret) > return ret; > > + ret = tdmrs_set_up_pamt_all(tdmr_list, tmb_list, > + sysinfo->pamt_entry_size); > + if (ret) > + return ret; > /* > * TODO: > * > - * - Allocate and set up PAMTs for each TDMR. > * - Designate reserved areas for each TDMR. > * > * Return -EINVAL until constructing TDMRs is done > @@ -547,6 +747,11 @@ static int init_tdx_module(void) > * Return error before all steps are done. > */ > ret = -EINVAL; > + if (ret) > + tdmrs_free_pamt_all(&tdx_tdmr_list); > + else > + pr_info("%lu KBs allocated for PAMT.\n", > + tdmrs_count_pamt_pages(&tdx_tdmr_list) * 4); Why not put the pr_info right after the 'if (ret)' check following tdmrs_setup_pamt_all(). And make the tdmrs_free_pamt_all call unconditional. It seems the main reason for having a bunch of conditionals in the exit reason is that you share the put_online_mems(); in both the success and failure cases. If you simply add : put_online_mems(); return 0; // failure labels follow Then you can make do without the if (ret) checks and have straight line code doing the error handling. > out_free_tdmrs: > if (ret) > free_tdmr_list(&tdx_tdmr_list); > diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h > index c20848e76469..e8110e1a9980 100644 > --- a/arch/x86/virt/vmx/tdx/tdx.h > +++ b/arch/x86/virt/vmx/tdx/tdx.h > @@ -133,6 +133,7 @@ struct tdx_memblock { > struct list_head list; > unsigned long start_pfn; > unsigned long end_pfn; > + int nid; > }; > > struct tdmr_info_list {