From patchwork Wed Aug 11 21:07:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Moyer X-Patchwork-Id: 12431993 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7790EC432BE for ; Wed, 11 Aug 2021 21:06:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F04486101D for ; Wed, 11 Aug 2021 21:06:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F04486101D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 827FD6B0072; Wed, 11 Aug 2021 17:06:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D9A56B0073; Wed, 11 Aug 2021 17:06:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C7198D0001; Wed, 11 Aug 2021 17:06:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0140.hostedemail.com [216.40.44.140]) by kanga.kvack.org (Postfix) with ESMTP id 517C06B0072 for ; Wed, 11 Aug 2021 17:06:22 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id F14A9181C9645 for ; Wed, 11 Aug 2021 21:06:21 +0000 (UTC) X-FDA: 78464032962.07.35A4BDA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 8250110055AE for ; Wed, 11 Aug 2021 21:06:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628715980; 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; bh=Ge0GTZUIjxikgSWkPB8zfOtpvL+2/SFPvGVsbcuYMDw=; b=TioJd4tKo2tAa6ykiIeMHFWWandOn3T9Vs60ZZajmm6kjt9u2F1DXIlhuwrB3Hf7zt8lfN WfN5nDKulk0bSstFXafaWkJbaJ942im/OXbM/c8X21nEcolo/NePGVj+0j40NDuOKmdTt3 Z6wARcvK1Vu4UNCdDB8L5K1LQWpQ0G4= 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-489-06BHg_uoN0OVyFP1lRgvtA-1; Wed, 11 Aug 2021 17:06:19 -0400 X-MC-Unique: 06BHg_uoN0OVyFP1lRgvtA-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 F3531344B1; Wed, 11 Aug 2021 21:06:17 +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 2AFE11ABD8; Wed, 11 Aug 2021 21:06:13 +0000 (UTC) From: Jeff Moyer To: dan.j.williams@intel.com, David Hildenbrand , Thomas Gleixner Cc: 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: [patch, v2] x86/pat: pass valid address to sanitize_phys() X-PGP-KeyID: 1F78E1B4 X-PGP-CertKey: F6FE 280D 8293 F72C 65FD 5A58 1FF8 A7CA 1F78 E1B4 Date: 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 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TioJd4tK; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf12.hostedemail.com: domain of jmoyer@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=jmoyer@redhat.com X-Stat-Signature: hcq8tuo3iup434js4bwkh85xjn79yxkt X-Rspamd-Queue-Id: 8250110055AE X-Rspamd-Server: rspam05 X-HE-Tag: 1628715981-640704 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Dan Williams --- 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));