From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.37703.1639556330680639091 for ; Wed, 15 Dec 2021 00:18:51 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d79n5HF9; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639556329; 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=qCykZn3cWJuYSQKZAugbK577elS9yzZyOR6mMYijbEE=; b=d79n5HF9n/afofLJ+L0+oWuKxG9ETF/ahyi+HDa4QEY1poXsX/tg7Nfkz0RU84+a+qjLaJ 7hP7YH+OC7B84aP7Vvtm5fT6A9hYBTCDF340tLRwB0BostwbFtkrl1ssrOCeG8ptocmvyM P55U7hiBAqqUyNOj4tihRkE5iyfG6Io= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-52-Z8NwaHQ2MxCvcBwCM3JP5Q-1; Wed, 15 Dec 2021 03:18:46 -0500 X-MC-Unique: Z8NwaHQ2MxCvcBwCM3JP5Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4DCD081CCB4; Wed, 15 Dec 2021 08:18:45 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B92B07E5AC; Wed, 15 Dec 2021 08:18:44 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id DE49E180039F; Wed, 15 Dec 2021 09:18:42 +0100 (CET) Date: Wed, 15 Dec 2021 09:18:42 +0100 From: "Gerd Hoffmann" To: Min Xu Cc: devel@edk2.groups.io, Ard Biesheuvel , Jordan Justen , Brijesh Singh , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky Subject: Re: [PATCH V4 17/31] OvmfPkg: Update Sec to support Tdx Message-ID: <20211215081842.stsakfl3ub3thycu@sirius.home.kraxel.org> References: <1ecb7543dda024e55e9f7a0253b0af0c610407c4.1639399598.git.min.m.xu@intel.com> MIME-Version: 1.0 In-Reply-To: <1ecb7543dda024e55e9f7a0253b0af0c610407c4.1639399598.git.min.m.xu@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline > +EFI_STATUS > +EFIAPI > +BspAcceptMemoryResourceRange ( > + IN EFI_PHYSICAL_ADDRESS PhysicalAddress, > + IN EFI_PHYSICAL_ADDRESS PhysicalEnd > + ) > +{ > + EFI_STATUS Status; > + UINT32 AcceptPageSize; > + UINT64 StartAddress1; > + UINT64 StartAddress2; > + UINT64 StartAddress3; > + UINT64 TotalLength; > + UINT64 Length1; > + UINT64 Length2; > + UINT64 Length3; > + UINT64 Pages; > + > + AcceptPageSize = FixedPcdGet32 (PcdTdxAcceptPageSize); > + TotalLength = PhysicalEnd - PhysicalAddress; > + StartAddress1 = 0; > + StartAddress2 = 0; > + StartAddress3 = 0; > + Length1 = 0; > + Length2 = 0; > + Length3 = 0; > + > + if (TotalLength == 0) { > + return EFI_SUCCESS; > + } > + > + if ((AcceptPageSize == SIZE_4KB) || (TotalLength <= SIZE_2MB)) { > + // > + // if total length is less than 2M, then we accept pages in 4k > + // > + StartAddress1 = 0; > + Length1 = 0; > + StartAddress2 = PhysicalAddress; > + Length2 = PhysicalEnd - PhysicalAddress; > + StartAddress3 = 0; > + Length3 = 0; > + AcceptPageSize = SIZE_4KB; You've zero-initialized everything above, no need to do that again. You also can just use StartAddress1 + Length1 which uses 4k pages anyway. > + } else if (AcceptPageSize == SIZE_2MB) { > + // > + // Total length is bigger than 2M and Page Accept size 2M is supported. > + // > + if ((PhysicalAddress & ALIGNED_2MB_MASK) == 0) { The logic is rather messy. It should become much simpler if you update PhysicalAddress and TotalLength. You can also use the alignment macros. if (ALIGN_VALUE(PhysicalAddress, SIZE_2MB) != PhysicalAddress) { StartAddress1 = PhysicalAddress; Length1 = ALIGN_VALUE(PhysicalAddress, SIZE_2MB) - PhysicalAddress; PhysicalAddress += Length1; TotalLength -= Length1; } if (TotalLength > SIZE_2MB) { StartAddress2 = PhysicalAddress; Length2 = TotalLength & ~(UINT64)ALIGNED_2MB_MASK PhysicalAddress += Length2; TotalLength -= Length2; } if (TotalLength) { StartAddress3 = PhysicalAddress; Length3 = TotalLength; } take care, Gerd