Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp1134109lfv; Thu, 14 Apr 2022 08:23:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwghAWonj4sVPBgT07WcOIdHbwwjFzf8Pzyr2288SkHJ5V+ffmt7QktsDAC4WY43p5bLyq/ X-Received: by 2002:a17:902:e544:b0:158:a26a:d7c1 with SMTP id n4-20020a170902e54400b00158a26ad7c1mr7671603plf.4.1649949828545; Thu, 14 Apr 2022 08:23:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649949828; cv=none; d=google.com; s=arc-20160816; b=en2mfFE+XOkLDXv63WXec1Fy9h3qlAmBTZXCWve3a8f1YiX8qarLyr5kUIZ1Gz5fN/ u2gA+YhuOT3oBBm1tuxZNA1PsNenb2jME7NKIRbFz5122JUg0xGUeuG7ElW7W1fpNM1V ukfE++oKCrrITDCKO3CNKw/QIN+jE818ZLFJgCzqr3uiq0BR8jEADRNPO6YyqE8hTnG1 ZCVtONIxjNakvf2kqo3eOfp7sTUztx6sFEZsKv3wRGIfnlUY0JmJzPNAe6FNqG42lBDo WQlvzhj+3O4r5wEf8D01F7B2LE4EEKLGDH6HxsfdR1r6+Noy8rpnvTQ/AaQKWng7Jakg AWsA== 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=JPxYSYQoncUEUek4m2rXO0zF+W4S8J55DAkQgzl9qOc=; b=JG8w0+zNY4IpCmm/ptqSRHIJmyncYnoKv5Fh4mSGOybHgTPtV2uSdIEQF5cirhgY+g LzNEEhL2ItTsN+pXoXa2MtNmgB8X+CaDylXWUYUb5BHVyLpF+ukF6C3spC11EQ9MSLJp Dp1N6QKRKFgKy4RaMQ+y0vtHhvzH0MaAUHc27g0qn3cvkHrotirurWC6q3jNLJrtQYRH ZLVTXDUjCZQgJergpoGZZ+Q24JjvCkQL+7U4npCvN5oyTUeCt4oPjbTvg8bQa3efIvsa oRHMqfUBioh0LDJCImgrW+Lyp/BYI5fyJ0UxePrl9YXFNaDTqYjWHX3ky5qfcHvvzblG 8KPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=W9TShO5g; 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 z16-20020a63d010000000b003816043f0bfsi8286706pgf.692.2022.04.14.08.23.33; Thu, 14 Apr 2022 08:23:48 -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=W9TShO5g; 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 S236344AbiDNApY (ORCPT + 99 others); Wed, 13 Apr 2022 20:45:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbiDNApX (ORCPT ); Wed, 13 Apr 2022 20:45:23 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E07F222531; Wed, 13 Apr 2022 17:43:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649896980; x=1681432980; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=doUkUAIgXJ69drkRZDzCk6IXBWZ2q70KNvQLAmtwTE0=; b=W9TShO5gZ0PiWt2DVq5vl3Hv2dCq86RIXqXRix0fdwzjZvhfxDBuNLRi 8cAGriBL5FF1Nn7UK9w4Nz5btSz4HpQuLwJoZmlsdblBg4k6UIdinSuA2 LKPl0lK4EwCoYbFE3C+AG417EBCaUSzsO5AalMhyS0xVqVht988+ix99Z 95mAtoKB/6KXgkwS9jr5UdbQfpZpanytqMnUtIlhOqzNnPIpYjhfX3k0G ZAspqCuet8vaqi7F2dVp1vZtbQLwZGRHw84wNhC45KRr44MGHzUaLE36P Ru5nhqy3hFwttK3JNr+0pxvZ4uztpEAc0ssnUnf877XXI1rDJDthZ/e3i A==; X-IronPort-AV: E=McAfee;i="6400,9594,10316"; a="323257319" X-IronPort-AV: E=Sophos;i="5.90,258,1643702400"; d="scan'208";a="323257319" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2022 17:43:00 -0700 X-IronPort-AV: E=Sophos;i="5.90,258,1643702400"; d="scan'208";a="700467184" Received: from alison-desk.jf.intel.com (HELO alison-desk) ([10.54.74.41]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2022 17:42:59 -0700 Date: Wed, 13 Apr 2022 17:44:54 -0700 From: Alison Schofield To: "Fabio M. De Francesco" Cc: Mauro Carvalho Chehab , Sakari Ailus , Greg Kroah-Hartman , Hans Verkuil , Tsuchiya Yuto , Martiros Shakhzadyan , Hans de Goede , linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Ira Weiny , outreachy@lists.linux.dev Subject: Re: [PATCH] staging: media: atomisp: Use kmap_local_page() in hmm_store() Message-ID: <20220414004454.GA1243697@alison-desk> References: <20220413225531.9425-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220413225531.9425-1-fmdefrancesco@gmail.com> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Thu, Apr 14, 2022 at 12:55:31AM +0200, Fabio M. De Francesco wrote: > The use of kmap() is being deprecated in favor of kmap_local_page() > where it is feasible. The same is true for kmap_atomic(). > > In file pci/hmm/hmm.c, function hmm_store() test if we are in atomic > context and, if so, it calls kmap_atomic(), if not, it calls kmap(). > > First of all, in_atomic() shouldn't be used in drivers. This macro > cannot always detect atomic context; in particular, it cannot know > about held spinlocks in non-preemptible kernels. > > Notwithstanding what it is said above, this code doesn't need to care > whether or not it is executing in atomic context. 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, hmm_store()() is a function where the use > of kmap_local_page() in place of both kmap() and kmap_atomic() is > correctly suited. > > Convert the calls of kmap() / kunmap() and kmap_atomic() / > kunmap_atomic() to kmap_local_page() / kunmap_local() and drop the > unnecessary tests which test if the code is in atomic context. > Not specifically about this patch, but more generally about all such conversions - is there a 'proof' that shows this just works or do we need to test each one. If the latter, then how? > Signed-off-by: Fabio M. De Francesco > --- > drivers/staging/media/atomisp/pci/hmm/hmm.c | 14 ++------------ > 1 file changed, 2 insertions(+), 12 deletions(-) > > diff --git a/drivers/staging/media/atomisp/pci/hmm/hmm.c b/drivers/staging/media/atomisp/pci/hmm/hmm.c > index 46ac082cd3f1..54188197c3dc 100644 > --- a/drivers/staging/media/atomisp/pci/hmm/hmm.c > +++ b/drivers/staging/media/atomisp/pci/hmm/hmm.c > @@ -482,10 +482,7 @@ int hmm_store(ia_css_ptr virt, const void *data, unsigned int bytes) > idx = (virt - bo->start) >> PAGE_SHIFT; > offset = (virt - bo->start) - (idx << PAGE_SHIFT); > > - if (in_atomic()) > - des = (char *)kmap_atomic(bo->page_obj[idx].page); > - else > - des = (char *)kmap(bo->page_obj[idx].page); > + des = (char *)kmap_local_page(bo->page_obj[idx].page); > > if (!des) { > dev_err(atomisp_dev, > @@ -512,14 +509,7 @@ int hmm_store(ia_css_ptr virt, const void *data, unsigned int bytes) > > clflush_cache_range(des, len); > > - if (in_atomic()) > - /* > - * Note: kunmap_atomic requires return addr from > - * kmap_atomic, not the page. See linux/highmem.h > - */ > - kunmap_atomic(des - offset); > - else > - kunmap(bo->page_obj[idx].page); > + kunmap_local(des); > } > > return 0; > -- > 2.34.1 > >