Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp26931iol; Wed, 8 Jun 2022 20:42:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQu7RB+pps5ZjNg7eIIf6oJItlVXWz9Xc442HiKaBckWcVFXJhrNbo7CgiC1ga8EayBS9h X-Received: by 2002:a17:906:c1ca:b0:6fe:9c2a:8106 with SMTP id bw10-20020a170906c1ca00b006fe9c2a8106mr34095832ejb.383.1654746125587; Wed, 08 Jun 2022 20:42:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654746125; cv=none; d=google.com; s=arc-20160816; b=kbApufxvayBjRGfHwO06AgJAANgHJg4Pe2kKJjAj0wefNktxoV7yNKK0JK/l9Peekd 4f3tMwAdj+J5OaPG8yQwlwCuJ5HAGlQ6CYEL5Ko6aZkL3VG5KG+aaL/vdXgkev8le9c/ EBQ67/5PzJpTlFSIda9XH7w70EQT3h3zRdvQ3ryG/nbfgFSCXmqrGZtdj/wJaPubqyGp xHjwZqx0gkYTZnMsuV0i0EXv+SJv0c1KWOVQxxw1cGSorQrvNF/6cqvXhqZTBF1LZWnB llxua5wqeyQK0WEAKSFHjE6hGs86P/Q+mL0y1qqbsq1B5ewyXSXlkN2zBS+LEkV2k8Jc 3LeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=V3r2F/mY4AMt+LdsuHqidrC7Cb1PPDmF4NQ+S2A4wpw=; b=Cfc8qv7vdNr1CaS2SwTAjg9IExQbrZDCGhDkmc9H81DO2xOAKiz6m71fJCKpOp57JI k/lshGclJbWvTwmbzm0KccmCI3D2UhVuC9dEM3yYrtPdrdmCNHjqVlFmt6J1WDb/JJ5e LXCK9JehW60Mq/K9UD0p3n9VHm5C3DslkY6FjqizR6X17y+yL0FiS9oXvN9KPkSIJrH/ 4QezXDxHSyQWFwQajPSbwyWk0IwKQMb079W0OX7ke/lPEgmld5X7keXcNswono0rWkXq +DXvErqvebYUSf+jScjIw1nU0MBeqIvYgrL34iGmtdcnMsZKYYLpByDABwA5MZq/Ks5H uyvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fOSLufrM; 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 mp37-20020a1709071b2500b006e88579e94fsi2574936ejc.798.2022.06.08.20.41.40; Wed, 08 Jun 2022 20:42:05 -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=fOSLufrM; 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 S237203AbiFICxD (ORCPT + 99 others); Wed, 8 Jun 2022 22:53:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232169AbiFICwq (ORCPT ); Wed, 8 Jun 2022 22:52:46 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B47E41A15D2 for ; Wed, 8 Jun 2022 19:52:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654743165; x=1686279165; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dahg2OqaWWaJXneGpLZ3gIlIowGf6y2fYRmwNLKxzJQ=; b=fOSLufrM6fLUHzJYOrkWaUyTzFnr8JH1l4X99in2GxZ1EaI9WgdW1C2y eKvAms2gc1uqTDElEKEebEtqfPoHPNSRkz5ALh+nG89wtSOqdZG12gXIP ynSOtmQmoAnF90P9WGTakJzk/vVbOhwc6CBBVyKB+sut/KpVau6rnuHKn ZOOjd/q+V5OKskPoUd0/o1qZ9jkTIo2y8YnFO4jcbyT1i1OTKqWR5y4po 9+6fPk3feBrZqhlUdea0JB5ouKD7D/JEDlCyPuIUdWHTVzKSc39+2N712 QQ323dYRr1HRGzvwwf3QednUZggSm+TXsnbIELwSJgviXrR7YqyEkNwWf A==; X-IronPort-AV: E=McAfee;i="6400,9594,10372"; a="363452727" X-IronPort-AV: E=Sophos;i="5.91,287,1647327600"; d="scan'208";a="363452727" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2022 19:52:44 -0700 X-IronPort-AV: E=Sophos;i="5.91,287,1647327600"; d="scan'208";a="683711303" Received: from smsarifr-mobl.amr.corp.intel.com (HELO skuppusw-desk1.home) ([10.212.139.233]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2022 19:52:43 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "H . Peter Anvin" , Kuppuswamy Sathyanarayanan , "Kirill A . Shutemov" , Tony Luck , Andi Kleen , Kai Huang , Wander Lairson Costa , Isaku Yamahata , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, linux-kernel@vger.kernel.org Subject: [PATCH v8 3/5] x86/mm: Make tdx_enc_status_changed() vmalloc address compatible Date: Wed, 8 Jun 2022 19:52:18 -0700 Message-Id: <20220609025220.2615197-4-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220609025220.2615197-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20220609025220.2615197-1-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.5 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 set_memory_*crypted() APIs are used to change encryption or decryption page attributes for the given address. It also by default support the conversion for the vmalloc'ed memory address. In TDX Guest, tdx_enc_status_changed() function is triggered by set_memory_*crypted() APIs when converting memory from/to shared or private. Internally this function uses __pa() for physical address conversion, which breaks the vmalloc address compatibility of the set_memory_*crypted() APIs. So add support to fix the vmalloc'ed address compatibility issue. Acked-by: Wander Lairson Costa Signed-off-by: Kuppuswamy Sathyanarayanan --- arch/x86/coco/tdx/tdx.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 94542876f26a..445f58547776 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -15,6 +15,7 @@ #include #include #include +#include /* TDX module Call Leaf IDs */ #define TDX_GET_INFO 1 @@ -678,8 +679,14 @@ static bool try_accept_one(phys_addr_t *start, unsigned long len, */ static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc) { - phys_addr_t start = __pa(vaddr); - phys_addr_t end = __pa(vaddr + numpages * PAGE_SIZE); + phys_addr_t start, end; + + if (is_vmalloc_addr((void *)vaddr)) + start = vmalloc_to_pfn((void *) vaddr) << PAGE_SHIFT; + else + start = __pa(vaddr); + + end = start + numpages * PAGE_SIZE; if (!enc) { /* Set the shared (decrypted) bits: */ -- 2.25.1