Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp284323rwl; Thu, 30 Mar 2023 16:07:55 -0700 (PDT) X-Google-Smtp-Source: AKy350a7LwHbzdkoHDCiSMTOSx6v4or8Yyza97vEJuNi+zSsTTWEDnUGruGCK4Yu6ipWQyMUvLkC X-Received: by 2002:a17:906:297:b0:93e:22e6:e7d3 with SMTP id 23-20020a170906029700b0093e22e6e7d3mr2901812ejf.0.1680217675096; Thu, 30 Mar 2023 16:07:55 -0700 (PDT) Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jt15-20020a170906dfcf00b0092ca204119esi593965ejc.570.2023.03.30.16.07.30; Thu, 30 Mar 2023 16:07:55 -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=ZGfUDkhq; arc=fail (signature failed); 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 S231398AbjC3XCC (ORCPT + 99 others); Thu, 30 Mar 2023 19:02:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231342AbjC3XB7 (ORCPT ); Thu, 30 Mar 2023 19:01:59 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F00FD33C for ; Thu, 30 Mar 2023 16:01:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680217318; x=1711753318; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=4hOLgA+Dh5f9VPqlNLF9fSGTJwnl3alcZAymeCg0snA=; b=ZGfUDkhqHu+fedXKlibtMda+blAEMW8PbOsI+TdMVgkMXx+Yfb9YPkne wlSXkTCzGyDrDl5h0QN1R+Veqw/EQWliuJZLt1lB3JOV4fXZ3AWjguGwp fWFBDUb65jyq0ys/FdW6+DECtNxvGJCQCv9jXZFgDEkqeYAQZy2ZX/SQr TfGDtDQPDedyRJdqhg2BFd/ys9KaB3chWVgT78Wdpc6kJ1KwT3DlLePk4 UKrhM6eEtnGpiS2xj5G8SO49+hr5qrx1u9PNusam3pEtrvehON/SKByGr ohWAa18TS+66sfxbU2FwmjnUt60nvOtET4ij93aVVy/tvzg0HrELkJACf g==; X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="427581164" X-IronPort-AV: E=Sophos;i="5.98,306,1673942400"; d="scan'208";a="427581164" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 16:01:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10665"; a="795863344" X-IronPort-AV: E=Sophos;i="5.98,306,1673942400"; d="scan'208";a="795863344" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmsmga002.fm.intel.com with ESMTP; 30 Mar 2023 16:01:57 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 30 Mar 2023 16:01:57 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 30 Mar 2023 16:01:56 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21 via Frontend Transport; Thu, 30 Mar 2023 16:01:56 -0700 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (104.47.73.48) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.21; Thu, 30 Mar 2023 16:01:56 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xm0/P9Uec3wNaW1WkXpwxsb0VHXvXfqnojmrCNRFlrMkyg2MCoikgllCyZjHc8sajNJWeHa06eARRZwTlL9NpivRkQLkn0L+zPSntD7ujH1TjwpFraarA2l+J4N6jNvv4Oy48trLIOvDaDT+x2aPqE23+Lawwsi3w9oNsyepPA3whb2XfqxmU1k1F+eo+QBbEikRg3AlD6SN4Vx0NQS+VA58cfMGx5a0CyJHnoCBxd+u8D0X1yL2dOoylk5WL2Rkzcd/70LV2lkJ/D3tOLJWsYRQl41yaq3juxHBiJFbekTFOmFYiKawizqEb66anhuiECmG5L3nnFRvHLTWX76XMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tls4RWxAdWT9FuT2t+XBhhorUIaHoYp/tcf6Ad9qOvI=; b=Q1+3m0U3g2Z/+APa64iuSBYd61Y/lDA20qmSl2mUUr8Xl2bY6HFFp7H0T5xjOak70H5daqDpcU7uXyR32K2lXZoIG8zQcJXBjv32YGKtBU7tOlK8wznLUNRhV/ancQcrlJetkzShxd1wjtDEYLjo6g6k86Jjl2XwwWZsP/NzEC1qojb/Jb7Guz+bXuUf8+0ZgSfu9FQj1eiuQeD964yWFTC/lDSC8ZZ3crRSYLj7CKEzXG7aorDmkw7bhCoKEPRq8PbuMEoLQ7SeVj2t10jxcQf9Sym1zH7Kl6+9MmQQejEuayqS4EYw7wROVD0jWCWHzS38PeH+/1X6c6/7ZYXpKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from SA1PR11MB6733.namprd11.prod.outlook.com (2603:10b6:806:25c::17) by BL1PR11MB5415.namprd11.prod.outlook.com (2603:10b6:208:315::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.20; Thu, 30 Mar 2023 23:01:50 +0000 Received: from SA1PR11MB6733.namprd11.prod.outlook.com ([fe80::c5b2:6996:5aee:91db]) by SA1PR11MB6733.namprd11.prod.outlook.com ([fe80::c5b2:6996:5aee:91db%5]) with mapi id 15.20.6222.033; Thu, 30 Mar 2023 23:01:50 +0000 Date: Thu, 30 Mar 2023 16:01:44 -0700 From: Ira Weiny To: Zhao Liu , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Matthew Auld , Thomas =?iso-8859-1?Q?Hellstr=F6m?= , Nirmoy Das , Maarten Lankhorst , Chris Wilson , Christian =?iso-8859-1?Q?K=F6nig?= , , , CC: Ira Weiny , "Fabio M . De Francesco" , Zhenyu Wang , Zhao Liu , Dave Hansen Subject: Re: [PATCH v2 2/9] drm/i915: Use memcpy_[from/to]_page() in gem/i915_gem_pyhs.c Message-ID: <642614d888783_375f7e294a5@iweiny-mobl.notmuch> References: <20230329073220.3982460-1-zhao1.liu@linux.intel.com> <20230329073220.3982460-3-zhao1.liu@linux.intel.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20230329073220.3982460-3-zhao1.liu@linux.intel.com> X-ClientProxiedBy: SJ0PR03CA0064.namprd03.prod.outlook.com (2603:10b6:a03:331::9) To SA1PR11MB6733.namprd11.prod.outlook.com (2603:10b6:806:25c::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA1PR11MB6733:EE_|BL1PR11MB5415:EE_ X-MS-Office365-Filtering-Correlation-Id: 484c729f-78cf-47b5-8f62-08db3172bea7 X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RMT2BsLRPAUl6zsL9LpzetC1w8gRZ6VuFiVnWCFnmbm5F0s8qR3mDb+4Zukyax/XNifMJB/vgyt15OZjDkYjC4IMomsXWmxYKVEDdKeZCejGrwK07Pi2zBxmZ3nPk4uZcBkVEiSVZU3zz9AxnN86cZOyOfDcE1o2DFGKErJtT28PPOy/dGQXri+IPwQc7gXvnioHpOumu4j+KbqKPtuqBjL44vP+URhckEpHVEddlteUhO8ymcoz/h/44X7KdpoIQ8J0KCR1T8Adai10z4ojq8GlMdmtghGh0pMeiDBF6stcnHfZ2kfEPkAxulQGm4ZRHAtlXMhaOBmsUAvPSElagAIMAUukogA6WATkXBBzmIoQDgOdNiJ+2SGXs+dvkY60RElhmejBzEDjMNMT9XaoVdtziaDqio5LGfj2E5fPkgPr1MV4IljWmwWN0kSzVth724lr2zt7tNrJOJ+7xOVU9onJ+fOk8tij0J2JbyFWg+67KsuppWNAs5TfQxOgKtuDF7+FRO1ef129zfyn/t6W+EeIz78Ra9a2cp/NGFNlIxyGC3zsKXp5G4x86mswY1KbO0wHjaRtDXOOGDcr3QS1Lu+Sl5WeKL6qdJN+4lFEDH4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA1PR11MB6733.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(376002)(366004)(136003)(396003)(346002)(451199021)(110136005)(54906003)(478600001)(316002)(6666004)(83380400001)(186003)(82960400001)(921005)(5660300002)(966005)(9686003)(26005)(6512007)(6486002)(7416002)(38100700002)(6506007)(8936002)(2906002)(44832011)(66556008)(41300700001)(66476007)(66946007)(8676002)(4326008)(86362001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?+OMcWCILWKeu+jLzkezLNyJInJfIao9P+LKlNeNgfB+1qBoO1H84+fc06gjI?= =?us-ascii?Q?Fwum+O2LqPH3uOVdIueRPwq7GB7yS95cpCT6r0bMW/cB+/LHuSRYCnGI+rii?= =?us-ascii?Q?jgSJq53oLejbQfhHqTGlSw9RUf8fgh4JCAro62oS21BJkUxdIQ96o9eZ/+xS?= =?us-ascii?Q?VTxEJgUaWrI4UZ3ukPVXyGGNJFBp5eZY7bymwz+SdwLDVrE1X40FetpUy5Uo?= =?us-ascii?Q?X0btZeNVeCYhXvn2wrhLzOT56rkgUKc+CEKl11cPsRy7Az0UUEs7Kzd+RbN8?= =?us-ascii?Q?/7J3/DdNPPHcoRs9s/ZxoJmv2pexxe5gUj3cDMJifFMqsuAB5hCtYUL7x10l?= =?us-ascii?Q?kJj28kZUwEobr0xOglPQvENGyvINuIfy4F12VhJU6ChsaYCdI4zVxCKAbgon?= =?us-ascii?Q?jtQ8HuPB54gR7PnJ+/6HOi18uxwJH7XhKlXsJMzbfAopce2Ky6n2NnsfT2U3?= =?us-ascii?Q?xhnsjh83KZGVa3T971TOTKAkr8G5VhfxD70Ci+X2FOskGV8HaaSZFFXP/3mb?= =?us-ascii?Q?6VkBei5qm0Kb4C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vUbxG6?= =?us-ascii?Q?EFm8l0QsZy5agc5pZAp2jOSiDJLYfNtXcrL/cuJjdoKxRyXcbbzOnuilZXdP?= =?us-ascii?Q?UB0dPzL1U1IrHbr954CKnU6Q8sl6IjI9gmVJjOYiG2pM+D+0dQRDmjIC/myg?= =?us-ascii?Q?S5S0I/tqH5pYuQltaKMNcnnXIBCZ4bgbmoTPpYKN?= X-MS-Exchange-CrossTenant-Network-Message-Id: 484c729f-78cf-47b5-8f62-08db3172bea7 X-MS-Exchange-CrossTenant-AuthSource: SA1PR11MB6733.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2023 23:01:50.4198 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vEP5LmMAkugoC/nTtWufwR9kz7RVb/hjTnC27vsDGM7UglfsfSYnTLLJa9fOuWevIJe4nAztmAYYPAPYFNUZPQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR11MB5415 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=unavailable 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 Zhao Liu wrote: > From: Zhao Liu > > The use of kmap_atomic() is being deprecated in favor of > kmap_local_page()[1], and this patch converts the call from > kmap_atomic() + memcpy() to memcpy_[from/to]_page(), which use > kmap_local_page() to build local mapping and then do memcpy(). > > The main difference between atomic and local mappings is that local > mappings doesn't disable page faults or preemption (the preemption is > disabled for !PREEMPT_RT case, otherwise it only disables migration). > > With kmap_local_page(), we can avoid the often unwanted side effect of > unnecessary page faults and preemption disables. > > In drm/i915/gem/i915_gem_phys.c, the functions > i915_gem_object_get_pages_phys() and i915_gem_object_put_pages_phys() > don't need to disable pagefaults and preemption for mapping because of > 2 reasons: > > 1. The flush operation is safe. In drm/i915/gem/i915_gem_object.c, > i915_gem_object_get_pages_phys() and i915_gem_object_put_pages_phys() > calls drm_clflush_virt_range() to use CLFLUSHOPT or WBINVD to flush. > Since CLFLUSHOPT is global on x86 and WBINVD is called on each cpu in > drm_clflush_virt_range(), the flush operation is global. > > 2. Any context switch caused by preemption or page faults (page fault > may cause sleep) doesn't affect the validity of local mapping. > > Therefore, i915_gem_object_get_pages_phys() and > i915_gem_object_put_pages_phys() are two functions where the uses of > local mappings in place of atomic mappings are correctly suited. > > Convert the calls of kmap_atomic() / kunmap_atomic() + memcpy() to > memcpy_from_page() and memcpy_to_page(). > > [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com > > v2: > * Used memcpy_from_page() and memcpy_to_page() to replace > kmap_local_page() + memcpy(). > * Dropped hot plug related description since it has nothing to do with > kmap_local_page(). > * Added description of the motivation of using kmap_local_page(). > > Suggested-by: Dave Hansen > Suggested-by: Ira Weiny Reviewed-by: Ira Weiny