Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp296719rwb; Wed, 28 Sep 2022 02:53:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4q1nL1g59iyPJQuwojwvf58BYQbIHoIf6pXzurA4/qFSkorbF6WtvsoLFwcyx/+ncQoBU9 X-Received: by 2002:a17:907:3e06:b0:733:693:600e with SMTP id hp6-20020a1709073e0600b007330693600emr25444900ejc.410.1664358781411; Wed, 28 Sep 2022 02:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664358781; cv=none; d=google.com; s=arc-20160816; b=gcqQ9H5ThrEZE0xgo9pDELUZz7cVzSoeinTQxMe6CqwFbgSEecU48q2oz+FzcJLhIp B4pxAxRPIaxXXlNIvlHIDPQksiC+6Gxnm6MUVcoyl97xVjDpn0TZjJg69NCQznIhBTdg AhyWk8WnlQw2h99Sy1TWDKzMpO62KcfoffJWLlnwLKnOkfGZYCnkXzsqzJtTIWJ6cn8B UDHYzwHBdXDRlXEpqKYH8Y6Ei5OujQorF5gU/b26TjfdsAU0n+vvAy8vmJROBRDo19wh tumHoQbUKLQFf44kFtwR631L7jUoACiQkCRMPiKVLDTcrFoABwEcecjjc4sYQHMUsYBZ Oxkw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=R30eZiwx4s6me84/HjImG2TrFFCldNtgCP53glvMF8c=; b=uHiQnotdLm1/p/mREJlLVmCTcsn5uQrWPv8RqAAPdA1/UuIiiW4V9R/5Q1uPL7hLjG 3ZzA9misO1m+9eF14CFSsFcw9+ESVyZVbYngTW6o3aVc0Ld7GSJRBt2sOW8auyA1MHmd +QXBlOmAkWorJqEBVjfXaSt6N47CKYxIiOzRPEKDccoY/r8848hCq/PaxICoOylcBOcW 2YkrcarpdnZVRVkFX8SMuuXHsgs4LSs5P1qkaGwb7PgS1uIhp3h/qr8cN4lLHbIfHK0a 3vDyAMhcMi1kYHcnr95ApaDwQV4NbU1+uUUUr0IbLkaGWeY8uVDP+9KSWIDuoJ9fcawM WjQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="KXyyB/rX"; 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 b11-20020a056402084b00b00447e721d3adsi5608994edz.275.2022.09.28.02.52.35; Wed, 28 Sep 2022 02:53:01 -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="KXyyB/rX"; 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 S233695AbiI1JW5 (ORCPT + 99 others); Wed, 28 Sep 2022 05:22:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233644AbiI1JWy (ORCPT ); Wed, 28 Sep 2022 05:22:54 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EEF7AC39C; Wed, 28 Sep 2022 02:22:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664356973; x=1695892973; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=LboepUjmxKb4jCu41mnETf1wIRYGxkuhefbkTgfmYdc=; b=KXyyB/rXIQAcDxEt2/PoNm8eb2xzIKs/hx/bugKwxKf0S0FNSQmkCoCX TV6CfMmSKQvFhxVDCVZT/DPbiMX3BvONaRWfIsLvQZMTlAxhIFciV7osL cYppHLEXnoPAZh0uu/jHqkdW05FXwKGrllDAhob8HpPCE7qxA0qM6WCNO Xa+3lK8vx8sT7qXIWfI9XTF91zf6Il+suxgVEzbobfZ4DQA+Np1qoIeHk E4x1Ry9+1u5Pg65GPwIK3WE8odV0lrX/W+hYfvQRACdbvCLh/2vSL6hdr 5+2kr4bot43s9xaUcKQT2LEILEtu3RytZOtZFteNzQYOi+VUwxSu+hiUE w==; X-IronPort-AV: E=McAfee;i="6500,9779,10483"; a="284685090" X-IronPort-AV: E=Sophos;i="5.93,351,1654585200"; d="scan'208";a="284685090" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 02:22:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10483"; a="572967241" X-IronPort-AV: E=Sophos;i="5.93,351,1654585200"; d="scan'208";a="572967241" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.132]) by orsmga003.jf.intel.com with ESMTP; 28 Sep 2022 02:22:49 -0700 From: Zhao Liu To: Sean Christopherson , 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 Cc: Ira Weiny , "Fabio M . De Francesco" , Zhenyu Wang , Zhao Liu , Dave Hansen Subject: [PATCH v2] KVM: SVM: Replace kmap_atomic() with kmap_local_page() Date: Wed, 28 Sep 2022 17:27:48 +0800 Message-Id: <20220928092748.463631-1-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE 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 From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1]. The main difference between kmap_atomic() and kmap_local_page() is the latter allows pagefaults and preemption. There're 2 reasons we can use kmap_local_page() here: 1. SEV is 64-bit only and kmap_locla_page() doesn't disable migration in this case, but here the function clflush_cache_range() uses CLFLUSHOPT instruction to flush, and on x86 CLFLUSHOPT is not CPU-local and flushes the page out of the entire cache hierarchy on all CPUs (APM volume 3, chapter 3, CLFLUSHOPT). So there's no need to disable preemption to ensure CPU-local. 2. clflush_cache_range() doesn't need to disable pagefault and the mapping is still valid even if sleeps. This is also true for sched out/in when preempted. In addition, though kmap_local_page() is a thin wrapper around page_address() on 64-bit, kmap_local_page() should still be used here in preference to page_address() since page_address() isn't suitable to be used in a generic function (like sev_clflush_pages()) where the page passed in is not easy to determine the source of allocation. Keeping the kmap* API in place means it can be used for things other than highmem mappings[2]. Therefore, sev_clflush_pages() is a function that should use kmap_local_page() in place of kmap_atomic(). 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 [2]: https://lore.kernel.org/lkml/5d667258-b58b-3d28-3609-e7914c99b31b@intel.com/ Suggested-by: Dave Hansen Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu --- Suggested by credits: Dave: Referred to his explanation about cache flush and usage of page_address(). Ira: Referred to his task document, review comments and explanation about cache flush. Fabio: Referred to his boiler plate commit message. --- Changes since v1: * Add the explanation of global cache flush for sev_clflush_pages() in commit message. * Add the explanation why not use page_address() directly. --- 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); - kunmap_atomic(page_virtual); + kunmap_local(page_virtual); cond_resched(); } } -- 2.34.1