Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp847219pxb; Fri, 22 Apr 2022 12:29:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzD0/5Q1foSQQyFni9VXKVlQkkVGF0Zyjb5CuGasSh2XZ77TA11Hr/kzpocflNyI8/wZqHR X-Received: by 2002:a17:902:6acc:b0:149:8f60:a526 with SMTP id i12-20020a1709026acc00b001498f60a526mr5894849plt.25.1650655747027; Fri, 22 Apr 2022 12:29:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650655747; cv=none; d=google.com; s=arc-20160816; b=Hfp6ydJQT/Gqlm/kUUeTExoIntY/qiW16j7jmxg5EiYqo5TLVLB84FacZGVguIjYsp hEaCwMHGioT7hxeH5N9qurm7u/OYJ3PPZqGwBSQyrA+Ogde/nhmzIl4N71+w6Zdud3HV P29qpTj7BTjLYbvQuxJt+7nlfrXXWPuAAF6Ojg24sYbA4j6IK1HK6nw7TO6vfApcit8f QDjG8GuDaEiq7Q22mfnxoL3q2CG35CRTAYMMCodbUrEA2kDsVRtHPNM2metIY1C2iTNo XgjLUv1hvvHZ/FKtXVWyUIKeoPKmMHLuiMGe3tX46AdpnTj4XCbGeR1pG5QdlMi/4Obe 3DbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=+CoeG1wGEI8/gfMyxtQ5JH5NSEVqNFUDQuUEB1szdvM=; b=egAlXK9PXUfPpPDu4uMQEpIiFE+F5vLboLX2coF0EFcNuXAxnHQUBT5QNLqnB3cIZL dyW8P1QNuhlbnIdCsZtsYjp5AxvuGsoVtywQZxrzkWGM50pR4cTNyEo9+R30R9ZespsH BppWifUA8YynceyYzwv8iZAnTs8aQWse9m6qQmBIkWOqybWXF8N11eFQym8yaaZugrcv cKWzidnVRpQ/x5QvKkZqy8U3HlIAXwgApL7lLZmSpaypqqUhyl3NkuV+dG0Yi3CbZiIf ANAfFZi8RPiLIE22bA9U+T5acDsnU8IPoHLP8GtO6pfpvuxgSgGIjR7V07JcVIR87fb0 5raA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=AEhXO2mE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u42-20020a056a0009aa00b0050a631780bdsi10032393pfg.339.2022.04.22.12.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 12:29:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=AEhXO2mE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3AA5215B953; Fri, 22 Apr 2022 11:39:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379106AbiDTNa6 (ORCPT + 99 others); Wed, 20 Apr 2022 09:30:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379110AbiDTNay (ORCPT ); Wed, 20 Apr 2022 09:30:54 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A70BD4339B for ; Wed, 20 Apr 2022 06:28:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=+CoeG1wGEI8/gfMyxtQ5JH5NSEVqNFUDQuUEB1szdvM=; b=AEhXO2mE1hpaKTTPfhCAJm2kDZDm+IKMhPsQCDZfeqrnUOkvF3XHJSft 0uWekxsBgStNaOhDaWn4f9+SepJ845Q0i8JhNvEvztlACkGEvBkg8DZoe C2rKv55OG3gHEVEv077nOIw/KnN63OT80cFE6q4+X6CqIIdcGj2M3SCl5 U=; Authentication-Results: mail2-relais-roc.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=julia.lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="5.90,275,1643670000"; d="scan'208";a="32524915" Received: from 203.107.68.85.rev.sfr.net (HELO hadrien) ([85.68.107.203]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2022 15:28:03 +0200 Date: Wed, 20 Apr 2022 15:28:03 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: "Fabio M. De Francesco" cc: Julia Lawall , ira.weiny@intel.com, Alaa Mohamed , outreachy@lists.linux.dev, boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] xen: Convert kmap() to kmap_local_page() In-Reply-To: <2940450.687JKscXgg@leap> Message-ID: References: <20220419234328.10346-1-eng.alaamohamedsoliman.am@gmail.com> <2940450.687JKscXgg@leap> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-65486685-1650461283=:2937" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE 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 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-65486685-1650461283=:2937 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT On Wed, 20 Apr 2022, Fabio M. De Francesco wrote: > On mercoledì 20 aprile 2022 08:03:05 CEST Julia Lawall wrote: > > > > On Wed, 20 Apr 2022, Alaa Mohamed wrote: > > > > > kmap() is being deprecated and these usages are all local to the thread > > > so there is no reason kmap_local_page() can't be used. > > > > > > Replace kmap() calls with kmap_local_page(). > > > > OK, so from a Coccinelle point of view, could we do > > > > @@ > > expression e1,e2,x,f; > > @@ > > > > e1 = > > - kmap > > + kmap_local_page > > (e2) > > ... when != x = e1 // not stored in any location and not passed to > another function > > when != f(...,e1,...) > > when != x = e2 > > when != f(...,e2,...) > > -kunmap(e2) > > +kunmap_local(e1) > > > > julia > > > > I've never spent sufficient time to understand properly the syntax and > semantics of expressions of Coccinelle. However, thanks Julia, this code > looks good and can be very helpful. > > Only a minor objection... it doesn't tell when 'e2' has been allocated > within the same function where the kmap() call is. OK, thanks for pointing that out. That seems like a key point that should be mentioned in log messages. It's not even visible in the context lines around the patch. > > In the particular case that I cite above, I'd prefer to remove the > allocation of the page (say with alloc_page()) and convert kmap() /kunmap() > to use kmalloc() / kfree(). > > Fox example, this is done in the following patch: > > commit 633b0616cfe0 ("x86/sgx: Remove unnecessary kmap() from > sgx_ioc_enclave_init()") from Ira Weiny. > > Can Coccinelle catch also those special cases where a page that is passed > to kmap() is allocated within that same function (vs. being passed as > argument to this function) and, if so, propose a replacement with > kmalloc()? Sure. I'll take a look at the precise example Alaa started with and see if I can come up with something. thanks, julia --8323329-65486685-1650461283=:2937--