Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp725999pxb; Wed, 1 Sep 2021 08:41:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4EOVQTUKC6AocNOEqh4wWqckmptRgiCo94SuuqS/9a6faxb3SAnyocWmz9EdeWS3tVCmO X-Received: by 2002:a92:d646:: with SMTP id x6mr105267ilp.280.1630510904879; Wed, 01 Sep 2021 08:41:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630510904; cv=none; d=google.com; s=arc-20160816; b=zTUsJH7sKoORvB/7ddv+6PmH+PxpUmpgV/vkr24Q9RrZG1pVXnNv1ASyc9pV+5OWmF K+EimgOXZwJLmhEdeo8vlbX3DN0Lva7Q7EK37iNmKD92A3PAX9/LdpwG0VLB4tqtPZxu 4yMFGECZb+5un8zdBLAdyD3K8YvWzjdpwn3KotAT5Q7pgDvHQ8BYZqKieG4TnIjq6n/M 4GQIVJnIW8m5L/8Uxy4pQSuYnJ5SifH9K89Rpg3IcwCKuI7ECSQbbm1oHQuzAhPKrgkv DTw8/aTBKrf5+JZdOKiDkUmdUFzHhSYsrcB6wHPmg07uQFW4PKb575Z+PcwhrTVrnZCz m1KA== 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:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=5WinnYXvg2iYFpy0z2oAKoDwNk1Mt/0CpYI65fqO58k=; b=ojEPDrHgwrrai2ACpYxrom/Cl6tdH8KYNjWe3kcB3BdJw84AvswSeF0t/EAtYZtxz+ /2N3M1mTRUGqIuDgZVheBToc83Uud5EUt/W4PkhtL1nZw/SsjooyabsCSxp2lXBzImZv Yv+Owzvn7r/t9JUDsHcXzjF9ojmcXnE1SdyUK+LXdekX1T8cU005M0RldRdp0GcxzE2V lLa1LdIj3clSq5z2maDhDYc9p/p0OcOmaVbLhffdIXgLVhB0orcGq+wv1vQ6a4IVC9gi nyATCayxysujVnXQEpzkyHb6t/aB3iGeJ9o9WYjOI2LtMeonFSs+8usdnttto1gzbMwY Z2yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MToFF0kc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r25si312791ioh.63.2021.09.01.08.41.32; Wed, 01 Sep 2021 08:41:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MToFF0kc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343746AbhIAPlV (ORCPT + 99 others); Wed, 1 Sep 2021 11:41:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21952 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244612AbhIAPlU (ORCPT ); Wed, 1 Sep 2021 11:41:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630510823; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5WinnYXvg2iYFpy0z2oAKoDwNk1Mt/0CpYI65fqO58k=; b=MToFF0kc/fK9VUDSAqIGsnHQjGwstj6tWmS0qvh1bGEMT4MqZfMRBwgFlSdGFWnYCtsAtB bB5pfUvfQMPdCDdrrZy5/b8K2hrFAUWds4LvqcYuDFipeqN/i7tyVSXaxh0x6wA4Jfmheq 1gL1Pit0QsuA86++T8ybXRrEppCnjAk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-387-LWUEAZCJPDWgAxZ0z7TwRw-1; Wed, 01 Sep 2021 11:40:22 -0400 X-MC-Unique: LWUEAZCJPDWgAxZ0z7TwRw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C41CEFC80; Wed, 1 Sep 2021 15:40:19 +0000 (UTC) Received: from segfault.boston.devel.redhat.com (segfault.boston.devel.redhat.com [10.19.60.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BB32B6ACFF; Wed, 1 Sep 2021 15:40:08 +0000 (UTC) From: Jeff Moyer To: dan.j.williams@intel.com Cc: David Hildenbrand , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Tony Luck , Borislav Petkov , linux-edac@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [patch, v2] x86/pat: pass valid address to sanitize_phys() References: X-PGP-KeyID: 1F78E1B4 X-PGP-CertKey: F6FE 280D 8293 F72C 65FD 5A58 1FF8 A7CA 1F78 E1B4 Date: Wed, 01 Sep 2021 11:41:32 -0400 In-Reply-To: (Jeff Moyer's message of "Wed, 11 Aug 2021 17:07:37 -0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ping? Jeff Moyer writes: > The end address passed to memtype_reserve() is handed directly to > sanitize_phys(). However, end is exclusive and sanitize_phys() expects > an inclusive address. If end falls at the end of the physical address > space, sanitize_phys() will return 0. This can result in drivers > failing to load, and the following warning: > > [ 9.999440] mpt3sas version 29.100.01.00 loaded > [ 9.999817] mpt3sas_cm0: 64 BIT PCI BUS DMA ADDRESSING SUPPORTED, total mem (65413664 kB) > [ 9.999819] ------------[ cut here ]------------ > [ 9.999826] WARNING: CPU: 26 PID: 749 at arch/x86/mm/pat.c:354 reserve_memtype+0x262/0x450 > [ 9.999828] reserve_memtype failed: [mem 0x3ffffff00000-0xffffffffffffffff], req uncached-minus > [ 9.999828] Modules linked in: mpt3sas(+) bnxt_en(+) ahci(+) crct10dif_pclmul crct10dif_common nvme crc32c_intel libahci nvme_core libata raid_class scsi_transport_sas devlink drm_panel_orientation_quirks nfit libnvdimm dm_mirror dm_region_hash dm_log dm_mod > [ 9.999840] CPU: 26 PID: 749 Comm: systemd-udevd Not tainted 3.10.0-1077.el7_7.mpt3sas_test008.x86_64 #1 > [ 9.999842] Hardware name: Inspur SA5112M5/SA5112M5, BIOS 4.1.12 02/24/2021 > [ 9.999843] Call Trace: > [ 9.999851] [] dump_stack+0x19/0x1b > [ 9.999857] [] __warn+0xd8/0x100 > [ 9.999859] [] warn_slowpath_fmt+0x5f/0x80 > [ 9.999861] [] reserve_memtype+0x262/0x450 > [ 9.999867] [] __ioremap_caller+0xf4/0x330 > [ 9.999872] [] ? mpt3sas_base_map_resources+0x151/0xa60 [mpt3sas] > [ 9.999875] [] ioremap_nocache+0x1a/0x20 > [ 9.999879] [] mpt3sas_base_map_resources+0x151/0xa60 [mpt3sas] > [ 9.999884] [] ? __kmalloc+0x1eb/0x230 > [ 9.999889] [] mpt3sas_base_attach+0xf5/0xa50 [mpt3sas] > [ 9.999894] [] _scsih_probe+0x4ec/0xb00 [mpt3sas] > [ 9.999901] [] local_pci_probe+0x4a/0xb0 > [ 9.999903] [] pci_device_probe+0x109/0x160 > [ 9.999909] [] driver_probe_device+0xc5/0x3e0 > [ 9.999910] [] __driver_attach+0x93/0xa0 > [ 9.999912] [] ? __device_attach+0x50/0x50 > [ 9.999914] [] bus_for_each_dev+0x75/0xc0 > [ 9.999916] [] driver_attach+0x1e/0x20 > [ 9.999918] [] bus_add_driver+0x200/0x2d0 > [ 9.999920] [] driver_register+0x64/0xf0 > [ 9.999922] [] __pci_register_driver+0xa5/0xc0 > [ 9.999924] [] ? 0xffffffffc049afff > [ 9.999928] [] _mpt3sas_init+0x16e/0x1000 [mpt3sas] > [ 9.999933] [] do_one_initcall+0xba/0x240 > [ 9.999940] [] load_module+0x271a/0x2bb0 > [ 9.999946] [] ? ddebug_proc_write+0x100/0x100 > [ 9.999948] [] SyS_init_module+0xef/0x140 > [ 9.999954] [] system_call_fastpath+0x25/0x2a > [ 9.999955] ---[ end trace 6d6eea4438db89ef ]--- > [ 9.999957] ioremap reserve_memtype failed -22 > [ 10.000087] mpt3sas_cm0: unable to map adapter memory! or resource not found > [ 10.000334] mpt3sas_cm0: failure at drivers/scsi/mpt3sas/mpt3sas_scsih.c:10597/_scsih_probe()! > > (Note that this warning was from an older distribution kernel, so line > numbers and file names may not line up with the current tree.) > > Fix this by passing the inclusive end address to sanitize_phys(). > > Fixes: 510ee090abc3 ("x86/mm/pat: Prepare {reserve, free}_memtype() for "decoy" addresses") > Signed-off-by: Jeff Moyer > Reviewed-by: David Hildenbrand > > --- > v2: > - Add the warning splat to the commit log. (tglx) > - Use parenthesis when referring to function names. (tglx) > - Add a comment to the code. (tglx) > - Use inclusive/exclusive instead of interval notation. > > diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c > index 3112ca7786ed..4ba2a3ee4bce 100644 > --- a/arch/x86/mm/pat/memtype.c > +++ b/arch/x86/mm/pat/memtype.c > @@ -583,7 +583,12 @@ int memtype_reserve(u64 start, u64 end, enum page_cache_mode req_type, > int err = 0; > > start = sanitize_phys(start); > - end = sanitize_phys(end); > + > + /* > + * The end address passed into this function is exclusive, but > + * sanitize_phys() expects an inclusive address. > + */ > + end = sanitize_phys(end - 1) + 1; > if (start >= end) { > WARN(1, "%s failed: [mem %#010Lx-%#010Lx], req %s\n", __func__, > start, end - 1, cattr_name(req_type));