Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2129414rwe; Fri, 2 Sep 2022 08:57:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR4rPS3l0MncC7Q86vSrTz6TTMa7O/J/apqaaAHYZ9wcr19T0gujcPsXRfpgkjkZBWVoh02J X-Received: by 2002:a17:906:dd4:b0:741:9901:abb5 with SMTP id p20-20020a1709060dd400b007419901abb5mr17082629eji.321.1662134236290; Fri, 02 Sep 2022 08:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662134236; cv=none; d=google.com; s=arc-20160816; b=RDjsiWiuL3Tpxjr8qUswNZuPK/Haj4AY4dzIhcdMvh23/zjPVCvqSFSWA8YK+2fGy7 QVo2Pja5dijYGvqRWfdLbe/y1Mb18HGCgdV1lcAS2S0nXxldUbjciIGTX8tv2r6lQwaZ K2XPgqUP9c8Lilkr5Vh3l3hsMl/rc+XLrWuotvhotT2BkLY2acDAqZooonVBiIJrPo4D NTL2qhfwSNEKhSWhE8gJp58bSROKo74s/6AQ79XOh/EXE8milkcBdyFCtdUEcI/Lcm5p BoTHUfHeUSDDbBGzz+No9A+9UdDwbEDHmKOkKrg6B//G1O/Y++al4mfpCL7IWYAy7r9B qIhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Homh/XQpZ+In2jR8/vqW/AC2iNbM1vot2oHBjKvCuQQ=; b=ik/xA1NK3OMLevLWJlpKS61/6A8RumJhpeS0bCdRGjJEewonLH4m+r5uGTQaIONET6 dFiq7njITybDKD2JjId1qrVdQma66pS1CA9EyoPzRZjA9HXJfKlY4yJcA67TSyoKAohR 0bIzjIcCNDKhvK0L1Lf6ATIE2HsXexgVF+p3AFUrPH9fnK8TAxsV02s8r31nF/kjqupD ZubWQ54mVLhT9rVQoelSopyCjG/MglWOGGBAi9OwyF04mo2v4lLqOoazUGzA6pAFE5cp AKv9p6E/Md4CVb/u3wbcj/NIhSEeMGR8AFyGY5TWmuAYgUmNx5MWSyVc3VAYfMGdk5Re sISQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=EPFT3NDu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y26-20020a50e61a000000b00448988d5624si2005676edm.246.2022.09.02.08.56.30; Fri, 02 Sep 2022 08:57:16 -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=@google.com header.s=20210112 header.b=EPFT3NDu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236257AbiIBPdC (ORCPT + 99 others); Fri, 2 Sep 2022 11:33:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236326AbiIBPcb (ORCPT ); Fri, 2 Sep 2022 11:32:31 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E542048E8B for ; Fri, 2 Sep 2022 08:15:15 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id l5so2307448pjy.5 for ; Fri, 02 Sep 2022 08:15:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=Homh/XQpZ+In2jR8/vqW/AC2iNbM1vot2oHBjKvCuQQ=; b=EPFT3NDuhbIVJlt2/EAVLMfMNIs5hvQhEynJiMYPQ3cKDrSbf+mhQ5iuGBOgB0X0p+ GzSGq9MIItTvk6sw8KvHiv8sDrYAmL7XYhRWUEJB9o1vruTzW8l8FUn7k0/rWbupcCb3 qMTYbRjZDSdQjDe8u6LxAB1n1YFa4UHSWDOZgnwsJMkGhkIuI2N4Us+nLGErcoQZTmLZ BGbyWYDFVFisMW0SWsE4nTMIqgFPkkl2HNTT5gMcXxQkuNmq2Yiwjs3rTDCRVAkEgxTJ Vm2TSIYOOvrV9LzgjFfLq2nZK8uyRVP6rxmyjtwVnarcpyvTZmaGEl5OLaXKK53sw9qI MNmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=Homh/XQpZ+In2jR8/vqW/AC2iNbM1vot2oHBjKvCuQQ=; b=QtIgPTCQwvP9+xuu2F059n+rNUOyXQYrrdSGluClgnyBjlfNJlEZ99pLQCbmnvU/AG DA3qit7u3Dk2T70F/kUgpntRknXzwGQsDBwStaOnUOzimBIgXEH9kJ+s9RVSOLWniNOh yl1uT+TchD+mrV16mg5kjI8iJhDBUNRRrhw2zQ2fazENSzi+0Ol6xNUlc8teZdpcqlde 6XQt+ljZQzAkV/nbf40ccknxmiuzpMn9wuUafHmTdz7pbkqfEJvpWQ6bPx0cGZiSmjg5 G7VT511DJqxGw+UUcoN09Rzc6PwJYJZfqPVgrn+vt7QS682XQaGG9Igv4sQRAq7u0G13 g6Aw== X-Gm-Message-State: ACgBeo1oWjnfyW+PjX/fUoAQ55qnap6hb9iarrtemHLejoYvLgD4H+3v mZDnUFPdSSp3l3sgf67P2ju/p7xtRVsFXw== X-Received: by 2002:a17:90a:62cc:b0:1fa:c17d:de02 with SMTP id k12-20020a17090a62cc00b001fac17dde02mr5480681pjs.26.1662131713622; Fri, 02 Sep 2022 08:15:13 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id j14-20020a170902da8e00b0016ee328fd61sm1754765plx.198.2022.09.02.08.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 08:15:13 -0700 (PDT) Date: Fri, 2 Sep 2022 15:15:09 +0000 From: Sean Christopherson To: Zhao Liu Cc: Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ira Weiny , "Fabio M . De Francesco" , Zhenyu Wang , Zhao Liu Subject: Re: [PATCH] KVM: SVM: Replace kmap_atomic() with kmap_local_page() Message-ID: References: <20220902090811.2430228-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220902090811.2430228-1-zhao1.liu@linux.intel.com> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Fri, Sep 02, 2022, Zhao Liu wrote: > From: Zhao Liu > > The use of kmap_atomic() is being deprecated in favor of > kmap_local_page()[1]. > > In arch/x86/kvm/svm/sev.c, the function sev_clflush_pages() doesn't > need to disable pagefaults and preemption in kmap_atomic(). It can > simply use kmap_local_page() / kunmap_local() that can instead do the > mapping / unmapping regardless of the context. > > With kmap_local_page(), the mapping is per thread, CPU local and not > globally visible. Therefore, sev_clflush_pages() is a function where > the use of kmap_local_page() in place of kmap_atomic() is correctly > suited. > > Convert the calls of kmap_atomic() / kunmap_atomic() to > kmap_local_page() / kunmap_local(). > > [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com > > Suggested-by: Ira Weiny > Suggested-by: Fabio M. De Francesco > Signed-off-by: Zhao Liu > --- > Suggested by credits. > Ira: Referred to his task document and review comments. > Fabio: Referred to his boiler plate commit message. > --- > arch/x86/kvm/svm/sev.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c > index 28064060413a..12747c7bda4e 100644 > --- a/arch/x86/kvm/svm/sev.c > +++ b/arch/x86/kvm/svm/sev.c > @@ -465,9 +465,9 @@ static void sev_clflush_pages(struct page *pages[], unsigned long npages) > return; > > for (i = 0; i < npages; i++) { > - page_virtual = kmap_atomic(pages[i]); > + page_virtual = kmap_local_page(pages[i]); > clflush_cache_range(page_virtual, PAGE_SIZE); SEV is 64-bit only, any reason not to go straight to page_address()? diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 28064060413a..aaf39e3c7bb5 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -457,7 +457,6 @@ static void sev_unpin_memory(struct kvm *kvm, struct page **pages, static void sev_clflush_pages(struct page *pages[], unsigned long npages) { - uint8_t *page_virtual; unsigned long i; if (this_cpu_has(X86_FEATURE_SME_COHERENT) || npages == 0 || @@ -465,9 +464,7 @@ static void sev_clflush_pages(struct page *pages[], unsigned long npages) return; for (i = 0; i < npages; i++) { - page_virtual = kmap_atomic(pages[i]); - clflush_cache_range(page_virtual, PAGE_SIZE); - kunmap_atomic(page_virtual); + clflush_cache_range(page_address(pages[i]), PAGE_SIZE); cond_resched(); } } config KVM_AMD_SEV def_bool y bool "AMD Secure Encrypted Virtualization (SEV) support" depends on KVM_AMD && X86_64 <================================== > - kunmap_atomic(page_virtual); > + kunmap_local(page_virtual); > cond_resched(); > } > } > -- > 2.34.1 >