Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3942918rwb; Sun, 9 Oct 2022 14:20:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7NJ03ffzRgZ5vLR1aMG0NPWOFBvOIasohXCfZtezIE022oJHOGgLCiRbOldC5k9DyEshk0 X-Received: by 2002:a05:6402:2949:b0:451:fabf:d88a with SMTP id ed9-20020a056402294900b00451fabfd88amr14610624edb.324.1665350434138; Sun, 09 Oct 2022 14:20:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665350434; cv=none; d=google.com; s=arc-20160816; b=lb9p/V7FKox38+W8G1S7UeOMgIVCgBqPCEsF/vtwj88dl6UU6vMbT9M0Vg3DldIfsO H710EJklFZllgKwetO/YaZDv8T7vf45TAr1jHW8qUEb8HIwLaJryzGh5QK7/Th8LZeuA WThWsrkh85cIr7iRrm0fed5gAnv+iVXWHZUV9Gs8qVqj2AQwU2dQyMzwF+XKg6SU/L/v Q2m0s4EbiSj1QkLP5YppNNbU0S7ndO7HZV8S3orlfnL017aitHDz43NDmLpqZhRj0FSv PoVVYtCQEZVYobX4c5bEz8/jLtx70MbMyr4v7paV3Bhv0T+4mOe6dY667LdQREnd1IbC Zh7g== 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; bh=8aw+71CytpGk0aa1LMaSDXWBT629GJafQ2n8JcZFAks=; b=bzU4XMVEQk3NHZJVqW5RW+K5Tz2GSgScVavZdafjct9ZYcFTzyxucRDPBBvJP1PITF d6L0vvSF3mPMZBiLfSZ2GziKPRBcGMrc52N6YqRgUwZCXjoWi1JMO2LINdDoMhAG29bp JMzi8nfJLJpDxTezszbrPXkgM68lwbZI+wGKSdofLJrMQYdpZiqEAppLbDMlfBJWMqeE BXSeCtEFOAtUAElrA41lrsIq+jjakbHfEYBkFTSxiM405+HtPsNOQ8tj6D0g7he53qGW n/llGwUC3fWaSFCN+mqZMWeYvTILE5/Lv7gurhYQRLE6I7zvfeNlbAwHw89/cvRPdu9j qqDg== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ht21-20020a170907609500b0078db70cc9b8si1566224ejc.606.2022.10.09.14.20.07; Sun, 09 Oct 2022 14:20:34 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230037AbiJIUqj (ORCPT + 99 others); Sun, 9 Oct 2022 16:46:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbiJIUqh (ORCPT ); Sun, 9 Oct 2022 16:46:37 -0400 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCC5B248C0; Sun, 9 Oct 2022 13:46:36 -0700 (PDT) Received: by mail-wr1-f49.google.com with SMTP id a10so14380113wrm.12; Sun, 09 Oct 2022 13:46:36 -0700 (PDT) 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 :message-id:reply-to; bh=8aw+71CytpGk0aa1LMaSDXWBT629GJafQ2n8JcZFAks=; b=6lvs7B/Su132jEE0rPmbnBcanNWUHHxX2X/BGc5JxgA0Mtm5IlToIWfm2BB7nhjVd5 N7fdP1tqYE4wQpy6nVZTL2bl6fI79MLYmRBs5WS3GgSJ6/bWha9RkU/qNKADtUD01t6O uiBWdgmqOIVsfQbobwbkdWGC6dc/jcHTJdW4haaD4Ym+2Yx3WsGhUnFgNpVaklNgJ/+N PBO9nQYTQyIbGNWbFcjgAF5Ae5WjsCdYO7bd2SaRTJ6Y9gXyVsxchSJPMRE/v5CFaI7I ErH8IDyVmih8Pe12Fc5Jb7jV1PVmKrOUjM5W05EKuZzwyzsCTI5gTJyMzSpOaYwCC0dY NAyg== X-Gm-Message-State: ACrzQf0HC59NlMprFUjlFUn3j+yGUL42dx3sx4ikTFqFgrfGTM4HwYKk 1FOQOPIajVS5CTCByDBRj/Y= X-Received: by 2002:a05:6000:170b:b0:22e:44d0:6bae with SMTP id n11-20020a056000170b00b0022e44d06baemr9347156wrc.99.1665348395186; Sun, 09 Oct 2022 13:46:35 -0700 (PDT) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id q18-20020a05600c2e5200b003c65c9a36dfsm1767119wmf.48.2022.10.09.13.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Oct 2022 13:46:34 -0700 (PDT) Date: Sun, 9 Oct 2022 20:46:33 +0000 From: Wei Liu To: Zhao Liu Cc: Wei Liu , Ira Weiny , "Fabio M . De Francesco" , "K . Y . Srinivasan" , Haiyang Zhang , Stephen Hemminger , Dexuan Cui , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, Zhenyu Wang , Zhao Liu Subject: Re: [PATCH] x86/hyperv: Replace kmap() with kmap_local_page() Message-ID: References: <20220928095640.626350-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no 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 Thu, Oct 06, 2022 at 10:21:43PM +0800, Zhao Liu wrote: > On Mon, Oct 03, 2022 at 08:50:16AM +0000, Wei Liu wrote: > > Date: Mon, 3 Oct 2022 08:50:16 +0000 > > From: Wei Liu > > Subject: Re: [PATCH] x86/hyperv: Replace kmap() with kmap_local_page() > > > > On Wed, Sep 28, 2022 at 02:08:40PM +0000, Wei Liu wrote: > > > On Wed, Sep 28, 2022 at 05:56:40PM +0800, Zhao Liu wrote: > > > > From: Zhao Liu > > > > > > > > kmap() is being deprecated in favor of kmap_local_page()[1]. > > > > > > > > There are two main problems with kmap(): (1) It comes with an overhead as > > > > mapping space is restricted and protected by a global lock for > > > > synchronization and (2) it also requires global TLB invalidation when the > > > > kmap's pool wraps and it might block when the mapping space is fully > > > > utilized until a slot becomes available. > > > > > > > > With kmap_local_page() the mappings are per thread, CPU local, can take > > > > page faults, and can be called from any context (including interrupts). > > > > It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore, > > > > the tasks can be preempted and, when they are scheduled to run again, the > > > > kernel virtual addresses are restored and are still valid. > > > > > > > > In the fuction hyperv_init() of hyperv/hv_init.c, the mapping is used in a > > > > single thread and is short live. So, in this case, it's safe to simply use > > > > kmap_local_page() to create mapping, and this avoids the wasted cost of > > > > kmap() for global synchronization. > > > > > > > > > > The kmap call in that function is not performance critical in any way, > > > and at this point in the initialization process I don't expect there to > > > be any contention, so the downside of kmap is not really a concern here. > > > > > > That being said, kmap getting deprecated is a good enough reason to > > > switch to kmap_local_page. And I appreciate this well-written, > > > well-reasoned commit message. > > > > > > I will apply it to hyperv-next later -- I doubt people will object to > > > this change, but just in case. > > > > Applied to hyperv-next. Thanks. > > Sorry Wei, based on Ira and Fabio's comments, do you agree me to send a > follow on patch to remove that BUG_ON()? Or send the v2 patch? > I just sent a PR to Linus. That PR includes your v1 patch. While the code can be improved, BUG_ON that does nothing is harmless. You can send a follow-up patch to remove the BUG_ON. Thanks, Wei. > Thanks, > Zhao