Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp8272654rwd; Tue, 20 Jun 2023 12:40:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4hraalte2Ejcw8fpYpPtEM8GP01v2CR6++bE0A/2ez+NiNP1KRkuri/y6xijpT6GPvQS1X X-Received: by 2002:a05:6a20:6a2b:b0:10f:1d33:d667 with SMTP id p43-20020a056a206a2b00b0010f1d33d667mr17817965pzk.5.1687290056095; Tue, 20 Jun 2023 12:40:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687290056; cv=none; d=google.com; s=arc-20160816; b=kuTqHPX36g0cWZneOzMJcQMml5sUIQE8ZFzZyNwrTsm9RCOOmAbY+v6tAX7cEfT78S HL4J1tqo/q+abHMO8aZjw63Um5UY/VmIAMIuSpF9vY5UAQs5TJ3wtLuVZ+cFmnH1BHPl 3GpulcoBI9PRLp24GL7eAqPwJv9qKhl7aVI/8M+d+DYWfRT9qMFGhKpZ9WYPwZ3UnyZU OSwVPWjL42Hd8WADdsBnq0ibYQrva3bIOJ3fBEB/mh1snEeaIAKQ935wHftq8Zp9AO4Q KFkFsc0gdgFGDJMNsy/pDeF5gtbO3LBvIY2QhQfHt5UnC803IdaZOFe2h4equYD57CTu iA/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=0zaTsJ8L7mizH+7IKWykutN9uaNAVP+iS4OromAlfhc=; b=GcNWH9NjUXq1t9RSxUrwC/IUlsH0j23HBhMfpqWnCQ0w/nvsYN/UoIVyrJxyXw+PjJ ca9QRfB3QLgOqEPxBOkcnB5d4KmLcDS6IixMHjkuvTNA7IybfLo0V8lqVxortvyw1mzM XCCE83c7+MHESu2kN/yjuulOc0tSWfUoePihkiK/PewERTSkPQS4yYfcSaco/6GD4em6 D6IV3u0v96zKcd+W0h2DqzGhCfb06m1vAUdwk7V0bYuGma+KUu2o0qnejyriXSFRGIE7 vhhiJJA+WdDjfGbRTZqZiUdvjjSOnwmcVWEKoYXFRIfyxgy9C7AOcPFonFtrrsrWC60R U1nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fNfm000N; 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 i187-20020a6254c4000000b0066888630a21si2328057pfb.67.2023.06.20.12.40.43; Tue, 20 Jun 2023 12:40:56 -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=fNfm000N; 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 S229750AbjFTSem (ORCPT + 99 others); Tue, 20 Jun 2023 14:34:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229665AbjFTSel (ORCPT ); Tue, 20 Jun 2023 14:34:41 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D66D410C2; Tue, 20 Jun 2023 11:34:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687286079; x=1718822079; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=7wOYvg1PU199MGs3s9q0fJPuRo9zPR+Rxyq5xsvig9s=; b=fNfm000NvG30KuV79I1/O/qHl7r8GxEZ5uVLVzl4dyiwLeJuqphaj5jt E2RVHj2Gt8WfS9XiSbpOxSJU2gQoNHAw6y4rwwQTV/1i5D3MOJ+UoycuP flJisCPgeOsREcG2fYcXszrq4dsS6vUiI7tzx0371FSSlXsRgA/Jjl+PI oq3s7chx32cO5bXFAC1EfjfMaML7aeFmqKniuvQwZwEq7+ECewTJBvSS5 xFSuyIwc3L0O1PF77tSdlXb9cbgmUXGW5SM0lmQxO8A0mwp630nqXIe5E pm0E+3YOgPRU9J1AJ9YGupUmTRmWTY+towwa2So5xZr+QgmCD+XgvSf7c A==; X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="340291597" X-IronPort-AV: E=Sophos;i="6.00,257,1681196400"; d="scan'208";a="340291597" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 11:34:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="960883657" X-IronPort-AV: E=Sophos;i="6.00,257,1681196400"; d="scan'208";a="960883657" Received: from oyloh-mobl.amr.corp.intel.com (HELO [10.209.25.231]) ([10.209.25.231]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 11:34:18 -0700 Message-ID: Date: Tue, 20 Jun 2023 11:34:17 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.11.0 Subject: Re: [PATCH v8 2/2] x86/tdx: Support vmalloc() for tdx_enc_status_changed() Content-Language: en-US To: Dexuan Cui , ak@linux.intel.com, arnd@arndb.de, bp@alien8.de, brijesh.singh@amd.com, dan.j.williams@intel.com, dave.hansen@intel.com, dave.hansen@linux.intel.com, haiyangz@microsoft.com, hpa@zytor.com, jane.chu@oracle.com, kirill.shutemov@linux.intel.com, kys@microsoft.com, linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, luto@kernel.org, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, seanjc@google.com, tglx@linutronix.de, tony.luck@intel.com, wei.liu@kernel.org, x86@kernel.org, mikelley@microsoft.com Cc: linux-kernel@vger.kernel.org, Tianyu.Lan@microsoft.com, rick.p.edgecombe@intel.com References: <20230620154830.25442-1-decui@microsoft.com> <20230620154830.25442-3-decui@microsoft.com> From: Sathyanarayanan Kuppuswamy In-Reply-To: <20230620154830.25442-3-decui@microsoft.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,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 Hi, On 6/20/23 8:48 AM, Dexuan Cui wrote: > When a TDX guest runs on Hyper-V, the hv_netvsc driver's netvsc_init_buf() > allocates buffers using vzalloc(), and needs to share the buffers with the > host OS by calling set_memory_decrypted(), which is not working for > vmalloc() yet. Add the support by handling the pages one by one. > > Co-developed-by: Kirill A. Shutemov > Signed-off-by: Kirill A. Shutemov > Reviewed-by: Michael Kelley > Signed-off-by: Dexuan Cui > --- Looks good to me. Reviewed-by: Kuppuswamy Sathyanarayanan > arch/x86/coco/tdx/tdx.c | 35 +++++++++++++++++++++++++++++------ > 1 file changed, 29 insertions(+), 6 deletions(-) > > Changes in v2: > Changed tdx_enc_status_changed() in place. > > Changes in v3: > No change since v2. > > Changes in v4: > Added Kirill's Co-developed-by since Kirill helped to improve the > code by adding tdx_enc_status_changed_phys(). > > Thanks Kirill for the clarification on load_unaligned_zeropad()! > > Changes in v5: > Added Kirill's Signed-off-by. > Added Michael's Reviewed-by. > > Changes in v6: None. > > Changes in v7: None. > Note: there was a race between set_memory_encrypted() and > load_unaligned_zeropad(), which has been fixed by the 3 patches of > Kirill in the x86/tdx branch of the tip tree. > > Changes in v8: > Rebased to tip.git's master branch. > > diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c > index 0c198ab73aa7..a313d5ab42f1 100644 > --- a/arch/x86/coco/tdx/tdx.c > +++ b/arch/x86/coco/tdx/tdx.c > @@ -8,6 +8,7 @@ > #include > #include > +#include > #include > #include > #include > #include > @@ -752,6 +753,19 @@ static bool tdx_map_gpa(phys_addr_t start, phys_addr_t end, bool enc) > return false; > } > > +static bool tdx_enc_status_changed_phys(phys_addr_t start, phys_addr_t end, > + bool enc) > +{ > + if (!tdx_map_gpa(start, end, enc)) > + return false; > + > + /* shared->private conversion requires memory to be accepted before use */ > + if (enc) > + return tdx_accept_memory(start, end); > + > + return true; > +} > + > /* > * Inform the VMM of the guest's intent for this physical page: shared with > * the VMM or private to the guest. The VMM is expected to change its mapping > @@ -759,15 +773,24 @@ static bool tdx_map_gpa(phys_addr_t start, phys_addr_t end, bool enc) > */ > 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); > + unsigned long start = vaddr; > + unsigned long end = start + numpages * PAGE_SIZE; > > - if (!tdx_map_gpa(start, end, enc)) > + if (offset_in_page(start) != 0) > return false; > > - /* shared->private conversion requires memory to be accepted before use */ > - if (enc) > - return tdx_accept_memory(start, end); > + if (!is_vmalloc_addr((void *)start)) > + return tdx_enc_status_changed_phys(__pa(start), __pa(end), enc); > + > + while (start < end) { > + phys_addr_t start_pa = slow_virt_to_phys((void *)start); > + phys_addr_t end_pa = start_pa + PAGE_SIZE; > + > + if (!tdx_enc_status_changed_phys(start_pa, end_pa, enc)) > + return false; > + > + start += PAGE_SIZE; > + } > > return true; > } -- Sathyanarayanan Kuppuswamy Linux Kernel Developer