Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2840018imm; Sun, 5 Aug 2018 13:35:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeSfXpqqHvGVmgDTGvxPNuoDYsQYom/Rgxj2X5sR+zL6zreL5WpC4kEQB68C+JQPMaTs9y1 X-Received: by 2002:a63:4386:: with SMTP id q128-v6mr11996886pga.353.1533501302474; Sun, 05 Aug 2018 13:35:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533501302; cv=none; d=google.com; s=arc-20160816; b=agTwPoep9nZvPxmo7Uq73qUSl/0VBitGSYn2h3hFVjglsQtwXhqs0vwqyw+YKl5aDu hb78Okx5E4dJhUOhiCVVOu73sphJV5cKt4xSBCUEQg0+LX9JEs1Ea2H0MA9IhHrTMew7 7Nlp4XZw4CV5MNwl0ZPSlcvYW4wgYB7wwoTN7bYFbDtg/rfqa4fZgCS4MPkJWWjspGSr FRBDNeWWTfaEEMpPlW/lrYQGqtonNdosuWBG1Og14kCBTmDLUeqhqqD5nwjquzqmkh/T MVylbAGRRt6R7OD9JpgvYPBbbV7XKwvykuugi4iNDBjIQ43+xs6ExlNLtc5SC2tRpr8h Ap7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=zSUqWeZZEz/29GfVYS2NA/aiN4nDkKzoKNCvmrDcWVY=; b=vEAYVNVy0/u8DiS8pKwJNrkYZ+0qP/K4XJ/DZNSO9HPt/l8GGNfZOw3W/+/ouQNC7n 3+aJs0YKiYAzh9d/Y4cCj3uV5E8oMPvg/tsb1cGbJKS/g2tTvy7uMvj0383YLGQ6jF4K 6da8npa+PB+Z1JXyvW1w8+067l4jL/iElvAI4AG5yousvsaOanRKV+vUzPEOr5RUVz6D GlqrKNzxdtCEs6062NMpIpl4ecAK4q5/pX8UYPCFbyInRTJJ1QXa8uSNAauP0C8h2GmJ Jv7DAEDXNhNsMYpX83HUg2NNB2RZSiPBwVOBTK3ep7pHWAtSfLShI+5V2k41ULrtF8/K m2Xw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j10-v6si10823922pgi.500.2018.08.05.13.34.16; Sun, 05 Aug 2018 13:35:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727434AbeHEWiC (ORCPT + 99 others); Sun, 5 Aug 2018 18:38:02 -0400 Received: from terminus.zytor.com ([198.137.202.136]:34435 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726769AbeHEWiC (ORCPT ); Sun, 5 Aug 2018 18:38:02 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w75KVNOG590190 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 5 Aug 2018 13:31:23 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w75KVN4t590187; Sun, 5 Aug 2018 13:31:23 -0700 Date: Sun, 5 Aug 2018 13:31:23 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Dave Hansen Message-ID: Cc: luto@kernel.org, hughd@google.com, hpa@zytor.com, bp@alien8.de, aarcange@redhat.com, peterz@infradead.org, tglx@linutronix.de, jpoimboe@redhat.com, gregkh@linuxfoundation.org, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, ak@linux.intel.com, mingo@kernel.org, dave.hansen@linux.intel.com, jgross@suse.com, keescook@google.com Reply-To: hughd@google.com, luto@kernel.org, gregkh@linuxfoundation.org, tglx@linutronix.de, jpoimboe@redhat.com, torvalds@linux-foundation.org, peterz@infradead.org, bp@alien8.de, aarcange@redhat.com, hpa@zytor.com, ak@linux.intel.com, linux-kernel@vger.kernel.org, mingo@kernel.org, keescook@google.com, jgross@suse.com, dave.hansen@linux.intel.com In-Reply-To: <20180802225826.1287AE3E@viggo.jf.intel.com> References: <20180802225826.1287AE3E@viggo.jf.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] mm: Allow non-direct-map arguments to free_reserved_area() Git-Commit-ID: 0d83432811f26871295a9bc24d3c387924da6071 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 0d83432811f26871295a9bc24d3c387924da6071 Gitweb: https://git.kernel.org/tip/0d83432811f26871295a9bc24d3c387924da6071 Author: Dave Hansen AuthorDate: Thu, 2 Aug 2018 15:58:26 -0700 Committer: Thomas Gleixner CommitDate: Sun, 5 Aug 2018 22:21:02 +0200 mm: Allow non-direct-map arguments to free_reserved_area() free_reserved_area() takes pointers as arguments to show which addresses should be freed. However, it does this in a somewhat ambiguous way. If it gets a kernel direct map address, it always works. However, if it gets an address that is part of the kernel image alias mapping, it can fail. It fails if all of the following happen: * The specified address is part of the kernel image alias * Poisoning is requested (forcing a memset()) * The address is in a read-only portion of the kernel image The memset() fails on the read-only mapping, of course. free_reserved_area() *is* called both on the direct map and on kernel image alias addresses. We've just lucked out thus far that the kernel image alias areas it gets used on are read-write. I'm fairly sure this has been just a happy accident. It is quite easy to make free_reserved_area() work for all cases: just convert the address to a direct map address before doing the memset(), and do this unconditionally. There is little chance of a regression here because we previously did a virt_to_page() on the address for the memset, so we know these are not highmem pages for which virt_to_page() would fail. Signed-off-by: Dave Hansen Signed-off-by: Thomas Gleixner Cc: keescook@google.com Cc: aarcange@redhat.com Cc: jgross@suse.com Cc: jpoimboe@redhat.com Cc: gregkh@linuxfoundation.org Cc: peterz@infradead.org Cc: hughd@google.com Cc: torvalds@linux-foundation.org Cc: bp@alien8.de Cc: luto@kernel.org Cc: ak@linux.intel.com Cc: Kees Cook Cc: Andrea Arcangeli Cc: Juergen Gross Cc: Josh Poimboeuf Cc: Greg Kroah-Hartman Cc: Peter Zijlstra Cc: Hugh Dickins Cc: Linus Torvalds Cc: Borislav Petkov Cc: Andy Lutomirski Cc: Andi Kleen Link: https://lkml.kernel.org/r/20180802225826.1287AE3E@viggo.jf.intel.com --- mm/page_alloc.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a790ef4be74e..3222193c46c6 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6939,9 +6939,21 @@ unsigned long free_reserved_area(void *start, void *end, int poison, char *s) start = (void *)PAGE_ALIGN((unsigned long)start); end = (void *)((unsigned long)end & PAGE_MASK); for (pos = start; pos < end; pos += PAGE_SIZE, pages++) { + struct page *page = virt_to_page(pos); + void *direct_map_addr; + + /* + * 'direct_map_addr' might be different from 'pos' + * because some architectures' virt_to_page() + * work with aliases. Getting the direct map + * address ensures that we get a _writeable_ + * alias for the memset(). + */ + direct_map_addr = page_address(page); if ((unsigned int)poison <= 0xFF) - memset(pos, poison, PAGE_SIZE); - free_reserved_page(virt_to_page(pos)); + memset(direct_map_addr, poison, PAGE_SIZE); + + free_reserved_page(page); } if (pages && s)